package com.ubiperf.util;

import java.util.Enumeration;
import java.net.*;

public class NetworkCards {
	
	public static void showNetworkCards() {
		try{ 
		Enumeration<NetworkInterface> cardsList = NetworkInterface.getNetworkInterfaces();
		
		if (cardsList == null) {
	        System.out.println("--No interfaces found--");
	      } else {
	    	  while (cardsList.hasMoreElements()) {
	    		  NetworkInterface card = cardsList.nextElement();
	    		  System.out.println("Interface Name:" + card.getName());
	    		  System.out.println("Display Name:" + card.getDisplayName());
	    		  Enumeration<InetAddress> addressList = card.getInetAddresses();
	    		  if (!addressList.hasMoreElements()) {
	    	            System.out.println("\t(No addresses for this interface)");
	    	          }
	    		  while (addressList.hasMoreElements()) {
	    			  InetAddress address = addressList.nextElement();
	    			  System.out.print("\tAddress "
	    		                + ((address instanceof Inet4Address ? "(v4)"
	    		                    : (address instanceof Inet6Address ? "(v6)" : "(?)"))));
	    			  System.out.println(": " + address.getHostAddress());
	    			  System.out.println("\tHost Name:" + address.getHostName());
	    			  System.out.println("");
	    			  
	    		  }//end while
	    	  }//end while
	      }//end else
	}catch (SocketException se) {
		System.out.println("Error getting network interfaces:" + se.getMessage());
	}//end catch
	}//end method
	

}//end class


